CREATE PROCEDURE sp_ThemNguoiDung
	@Username char(15),
	@Password char(15),
	@Quyen int,
	@HoTen nvarchar(50),
	@CMND char(13),
	@DienThoai char(15),
	@Email char(30),
	@DiaChi nvarchar(50)
AS
BEGIN TRAN
	declare @Ma int
	set @Ma = 1
	while exists (SELECT * FROM NGUOIDUNG WHERE MaUser = @Ma)
		set @Ma = @Ma + 1
	INSERT INTO NGUOIDUNG VALUES(@Ma, @Username, @Password, @Quyen)
	INSERT INTO THONGTINUSER VALUES(@Ma, @HoTen, @CMND, @DienThoai, @Email, @DiaChi)
	if(@@error <> 0)
		raiserror('Khong the them nguoi dung',16,1)
COMMIT